﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraTreeList.Nodes;
using ElingAppSystemCtrls;
using DevExpress.XtraGrid.Views.Grid;

namespace HouseSecretary.Base
{
    public partial class GridChildForm : Base.BaseForm
    {

        /// <summary>
        /// 不记录日志
        /// </summary>
        public GridChildForm()
            : base()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <param name="isWriteLog"></param>
        public GridChildForm(bool isWriteLog)
            : base(isWriteLog)
        {
            InitializeComponent();
        }
        ///// <summary>
        ///// 初始化相关自定义列名
        ///// </summary>
        ///// <param name="gridView1"></param>
        ///// <param name="apsName">act_house_src_info-房源 act_purchase_info-求购 </param>
        //private void InitializeColumnName(GridView gridView1, string apsName)
        //{
        //    //系统字段属性列表
        //    var apsList = from c in Base.GlobalParams.GLOBAL_APSCATCOLLIST
        //                  where c.aps_tnam == apsName
        //                  select c;
        //    if (apsList.Count() > 0)
        //    {
        //        foreach (GridColumn col in gridView1.Columns)
        //        {
        //            List<Model.Apscatcol> selectApscatcollist = (from nm in apsList where nm.aps_cnam == col.FieldName select nm).ToList();
        //            if (selectApscatcollist.Count != 0)
        //            {
        //                Model.Apscatcol ApscatcolModel = selectApscatcollist[0];
        //                if (ApscatcolModel.aps_usrhdr != "" && ApscatcolModel.aps_usrhdr != null)
        //                {
        //                    col.Caption = ApscatcolModel.aps_usrhdr;
        //                }
        //            }
        //        }
        //    }

        //}
        /// <summary>
        /// 设置列是否可见
        /// </summary>
        /// <param name="colName"></param>
        /// <param name="visible"></param>
        /// <param name="gridView1"></param>
        protected void SetColumnVisible(string colName, bool visible, GridView gridView1)
        {
            if (gridView1.Columns[colName] != null)
            {
                gridView1.Columns[colName].Visible = visible;
            }
        }

        /// <summary>
        /// 设置列是否可修改
        /// </summary>
        /// <param name="colName"></param>
        /// <param name="enabled"></param>
        /// <param name="gridView1"></param>
        protected void SetColumnAllowEdit(string colName, bool enabled, GridView gridView1)
        {
            if (gridView1.Columns[colName] != null)
            {
                gridView1.Columns[colName].OptionsColumn.AllowEdit = enabled;
            }
        }
        /// <summary>
        /// 全部反选
        /// </summary>
        /// <param name="easGridControl1"></param>
        /// <param name="gridView1"></param>
        protected void SelectInverseSelectRowAll(ElingAppSystemCtrls.EASGridControl easGridControl1, GridView gridView1)
        {
            DataTable NewEditDT = (DataTable)easGridControl1.DataSource;
            gridView1.CloseEditor();
            gridView1.UpdateCurrentRow();
            for (int i = 0; i < NewEditDT.Rows.Count; i++)
            {
                if (NewEditDT.Rows[i]["xz"].ToString() == "1")
                {
                    NewEditDT.Rows[i]["xz"] = 0;
                }
                else
                {
                    NewEditDT.Rows[i]["xz"] = 1;
                }
            }
            easGridControl1.DataSource = NewEditDT;
        }
        /// <summary>
        /// 全选
        /// </summary>
        /// <param name="easGridControl1"></param>
        /// <param name="gridView1"></param>
        protected void SelectRowAll(ElingAppSystemCtrls.EASGridControl easGridControl1, GridView gridView1)
        {
            DataTable NewEditDT = (DataTable)easGridControl1.DataSource;
            gridView1.CloseEditor();
            gridView1.UpdateCurrentRow();
            for (int i = 0; i < NewEditDT.Rows.Count; i++)
            {
                NewEditDT.Rows[i]["xz"] = 1;
            }
            easGridControl1.DataSource = NewEditDT;
        }
        /// <summary>
        /// 取消选中
        /// </summary>
        /// <param name="easGridControl1"></param>
        /// <param name="gridView1"></param>
        protected void UnselectRow(ElingAppSystemCtrls.EASGridControl easGridControl1, GridView gridView1)
        {
            DataTable NewEditDT = (DataTable)easGridControl1.DataSource;
            gridView1.CloseEditor();
            gridView1.UpdateCurrentRow();
            for (int i = 0; i < NewEditDT.Rows.Count; i++)
            {
                NewEditDT.Rows[i]["xz"] = 0;
            }
            easGridControl1.DataSource = NewEditDT;
        }
      
        /// <summary>
        /// 递归加载树节点
        /// <creator>zhongyl</creator>
        /// <date>2012-01-11</date>
        /// </summary>
        /// <param name="dr"></param>
        /// <param name="ds"></param>
        /// <param name="Treelist"></param>
        /// <param name="NodeName"></param>
        /// <param name="tlstwylx"></param>
        private void BindingTree(DataRow dr, DataSet ds, TreeListNode Treelist, string NodeName, EASTreeList tlstwylx)
        {
            DataRow[] sondrlist = ds.Tables[0].Select("pre_house_admin_type_cd='" + dr["house_admin_type_cd"].ToString() + "'");
            foreach (DataRow sondr in sondrlist)
            {
                TreeListNode node = tlstwylx.AppendNode(new object[] { sondr["house_admin_type_name"], sondr["house_admin_type_cd"] }, Treelist, "");
                node.CheckState = CheckState.Unchecked;
                if (NodeName == sondr["house_admin_type_cd"].ToString())
                {
                    node.Selected = true;
                }
                BindingTree(sondr, ds, node, NodeName, tlstwylx);
            }
        }
        /// <summary>
        /// 选择框选中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void CheckBoxQueryCheckStateByValue(object sender, DevExpress.XtraEditors.Controls.QueryCheckStateByValueEventArgs e)
        {
            if (e.Value != null)
            {
                string val = e.Value.ToString();
                switch (val)
                {
                    case "True":
                        e.CheckState = CheckState.Checked;
                        break;
                    case "False":
                        e.CheckState = CheckState.Unchecked;
                        break;
                    case "Yes":
                        goto case "True";
                    case "No":
                        goto case "False";
                    case "1":
                        goto case "True";
                    case "0":
                        goto case "False";
                    case "Y":
                        goto case "True";
                    case "N":
                        goto case "False";

                    default:
                        e.CheckState = CheckState.Unchecked;
                        break;
                }
            }
            e.Handled = true;
        }
        /// <summary>
        /// 窗体退出,清空基类的数据对象
        /// </summary>
        protected void ClearDataFormClosed()
        {
            //house_admin_typeds = null;
            //EmpComBoList = null;
            //GeneralAddrList = null;
        }
    }
}
